import {SysDictTypeAdd, SysDictTypeData, SysDictTypeDetail, SysDictTypeParams} from "@/pages/system/dict/type/type";
import {request} from "@@/plugin-request/request";
import download from "@/utils/download";



export const sysDictTypePageList = async (sysDictTypeParams: SysDictTypeParams) => {
  return request<{
    data: {
      records: SysDictTypeData[],
      total: number,
    }
    success: boolean
  }>('/api/sys/dict/type/list', {
    method: 'POST',
    data: sysDictTypeParams
  });
}




export const sysDictTypeUpdate = async (sysDictTypeAdd: SysDictTypeAdd) => {
  return request<{
    data: string;
  }>('/api/sys/dict/type/update', {
    method: 'POST',
    data: sysDictTypeAdd
  });
}

export const sysDictTypeAdd = async (sysDictTypeAdd: SysDictTypeAdd) => {
  return request<{
    data: string;
  }>('/api/sys/dict/type/add', {
    method: 'POST',
    data: sysDictTypeAdd
  });
}

export const sysDictTypeRemove = async ( ids: (number | string)[] ) => {
  return request<{
    data: string;
  }>('/api/sys/dict/type/remove', {
    method: 'POST',
    data: {
      ids
    }
  });
}

export const sysDictTypeDetail = async (id: number) => {
  return request<{
    data: SysDictTypeDetail;
  }>('/api/sys/dict/type/detail', {
    method: 'POST',
    data: {
      id
    }
  });
}



export const sysDictTypeImport = async (formData: FormData) => {
  return request<{
    data: string;
  }>('/api/sys/dict/type/import', {
    method: 'POST',
    data: formData,
    requestType: "form"
  });
}


const sysDictTypeExport = async (ids: (number | string)[]) => {
  return request<{
    data: string;
  }>('/api/sys/dict/type/export', {
    method: 'POST',
    data: {ids},
    responseType: 'blob',
    getResponse: true,
  });
}

export const downloadSysDictTypeExport = async (ids: (number | string)[]) => {
  await sysDictTypeExport(ids).then(({data, response}) => {
    download(data, response)
  });
}


const sysDictTypeExportTemplate = async () => {
  return request<{
    data: string;
  }>('/api/sys/dict/type/export/template', {
    method: 'POST',
    responseType: 'blob',
    getResponse: true,
  });
}

export const downloadSysDictTypeExportTemplate = async () => {
  await sysDictTypeExportTemplate().then(({data, response}) => {
    download(data, response)
  });
}



